/**
 * 更新用户
 * @url admin/system/user/sys/update
 * @description 更新用户信息
 */
module.exports = {
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '更新成功' };
		
		// 业务逻辑开始-----------------------------------------------------------
		let {
			_id,
			nickname,
			mobile,
			email,
			role,
			status
		} = data;
		
		if (!_id) {
			return { code: -1, msg: '用户ID不能为空' };
		}
		
		// 构建更新数据
		let updateData = {};
		if (nickname !== undefined) updateData.nickname = nickname;
		if (mobile !== undefined) updateData.mobile = mobile;
		if (email !== undefined) updateData.email = email;
		if (role !== undefined) updateData.role = role;
		if (status !== undefined) updateData.status = status;
		
		// 更新用户信息
		await db.collection('uni-id-users').doc(_id).update(updateData);
		
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}

